package com.sesample.seandroidsample;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.View;
import android.widget.TextView;

public class EventDialogFragment extends DialogFragment {
  public final static String EXTRA_MESSAGE = "com.example.basic.EventDialogFragment.EXTRA_MESSAGE";

  public static EventDialogFragment newInstance(String message) {
    Bundle args = new Bundle();
    args.putString(EXTRA_MESSAGE, message);

    EventDialogFragment fragment = new EventDialogFragment();
    fragment.setArguments(args);
    return fragment;
  }

  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
    String message = getArguments().getString(EXTRA_MESSAGE);
    
    View eventMain = View.inflate(getActivity(), R.layout.dialog_event, null);
    TextView eventMessage = (TextView)eventMain.findViewById(R.id.event_message);
    eventMessage.setText(message);

    // Use the Builder class for convenient dialog construction
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.dialog_event_title)
    .setView(eventMain)
    .setPositiveButton(R.string.dialog_event_button_text, new DialogInterface.OnClickListener() {
      @Override
      public void onClick(DialogInterface dialog, int id) {
        // FIRE ZE MISSILES!
      }
    });
    // Create the AlertDialog object and return it
    return builder.create();
  }
}
